<template>
		<div class="ibox-content">
	  	<table class="form-table" style="margin-top: 5px">
			<thead>
			<tr v-show="opinionList.length>0">
				<th>任务名称</th>
				<th v-show="showCreateTime" >任务创建时间</th>
				<th>处理时间</th>
				<th v-show="showAssignInfo">候选人</th>
				<th >执行人</th>
				<th >处理状态</th>
				<th>备注/意见</th>
			</tr>
			</thead>
			<tr v-for="o in opinionList">
				<td	><span style="height: 6px">{{o.taskName}}</span> </td>
				<td v-show="showCreateTime" 	>{{o.createTime }}</td>
				<td >{{o.approveTime }}</td>
				<td v-show="showAssignInfo" >{{assignInfo(o.assignInfo)}}</td>
				<td	>{{o.approverName}}</td>
				<td 	>{{OpinionStatusKeyMap[o.status]}}</td>
				<td >{{o.opinion}}</td>
			</tr>
			<tr v-if="editCurrentTaskOpinion">
				<td><textarea placeholder="请录入审批意见" v-model="flowRequestParam.opinion"> </textarea></td>
			</tr>
		</table>
		</div>
</template>

<script>
import Vue from 'vue';

export default {
	props: ['flowRequestParam',"showCreateTime","showAssignInfo","editCurrentTaskOpinion"],
  	data :function () {
	    return {
	    	opinionList:[],
	    	OpinionStatusKeyMap:{}
	    }
	},
	created : function(){
		if(!this.flowRequestParam || !this.flowRequestParam.instanceId){
			return;
		}
 		
		var defer = Vue.baseService.postForm(__ctx+"/bpm/instance/getOpinion", {
			instId : this.flowRequestParam.instanceId,
			taskId : this.flowRequestParam.taskId ||''
		});
		var scope = this;
		$.getResultData(defer, function(data) {
			scope.opinionList = [];
			for(var j=0,item;item=data[j++];){
				if (item.assignInfo == "所有会签用户" && !item.approveTime) {
					return;
				}
				scope.opinionList.push(item);
			}
		})
		
		ToolsController.getEnum("com.dstz.bpm.api.constant.OpinionStatus").then(function(data) {
			for(var key in data){
				scope.OpinionStatusKeyMap[data[key].key] = data[key].value;
			}
		});
 	},
  	methods: {
  		assignInfo:function(info){
  			if (!info) {
				return "";
			}
			if(info.indexOf("-")==-1){
				return info;
			}
			var msg = "";
			angular.forEach(info.split(","), function(item) {
				if (!item) {
					return;
				}
				if (msg) {
					msg += "；";
				}
				var strs = item.split("-");
				var typeName = "";
				if (strs[0] === "user") {
					typeName = "[用户]";
				} else if (strs[0] === "role") {
					typeName = "[角色]";
				} else if (strs[0] === "group") {
					typeName = "[组]";
				} else if (strs[0] === "org") {
					typeName = "[组织]";
				} else if (strs[0] === "post") {
					typeName = "[岗位]";
					if (strs[2]) {
						return msg += typeName + strs[1] + "-" + strs[2];
					}
				} else if (strs[0] === "job") {
					typeName = "[职称]";
				}
				msg += typeName + strs[1];
			});
			return msg;
  		}
  	}
}
</script>
